import { Component } from "react";
import { GetAreaCityListData } from "@/network/area/model";
import { postAreaCookie } from "@/network/area/service";
import { Props, State } from "./model";
export default class Service extends Component<Props,State>{
   
    state: Readonly<State>={
        isVisible:false,
        areaCityList:[],
        currentArea:{
            key:0,
            value:"衢州市"
        }
    };
    setAreaCityList=async()=>{
        // const data = await getAreaCityList({
        //     provinceCode:330800
        // })
        const data=[{
            key:0,
            value:"衢州市"
        },{
            key:1,
            value:"市本级"
        },{
            key:2,
            value:"柯城区"
        },{
            key:3,
            value:"衢江区"
        },{
            key:4,
            value:"江山市"
        },{
            key:5,
            value:"龙游县"
        },{
            key:6,
            value:"常山县"
        }
        ,{
            key:7,
            value:"开化县"
        }
        ,{
            key:8,
            value:"智造新城"
        }
        ,{
            key:9,
            value:"智慧新城"
        }]

        this.setState({
            areaCityList:data as GetAreaCityListData
        })
    }

    setPostAreaCity=async()=>{
        postAreaCookie({
            areaId:this.state.currentArea.key
        })
    }
    componentWillMount = async()=>{
        this.setAreaCityList();
    (localStorage.getItem("currentArea") || localStorage.setItem("currentArea",JSON.stringify(this.state.currentArea)) || true) && this.setState({currentArea:JSON.parse(localStorage.getItem("currentArea") as string)})
        this.setPostAreaCity();
    }
}